package alvarodelrosal.chat.client.chataction.local;

import alvarodelrosal.chat.client.gui.MainWindow;
import alvarodelrosal.chat.client.gui.VentanaDeLogin;
import alvarodelrosal.chat.client.modelo.ChatUser;
import alvarodelrosal.chat.client.chataction.remote.ChatGetAllUsers;
import java.util.List;
import javax.swing.SwingUtilities;

public class ChatOkLogin implements ChatLocalAction {

    @Override
    public String getName() {
        return "OkLogin";
    }

    @Override
    public void doAction(List<String> parameters) {
        ChatUser user = new ChatUser(Integer.parseInt(parameters.get(0)),
                parameters.get(1), parameters.get(2), Boolean.parseBoolean(parameters.get(3)));
        
        ChatGetAllUsers allUsers = new ChatGetAllUsers();
        allUsers.doAction(null);

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                new MainWindow().setVisible(true);
                VentanaDeLogin.hacerInvisible();
            }
        });
        MainWindow.setUser(user);

    }
}
